<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="排序号" prop="sortNo">
						<el-input-number v-model="form.sortNo" placeholder="排序号"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="人员姓名" prop="userId">
						<select-hr-user-dialog v-model:userId="form.userId" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="薪资年度" prop="year">
						<el-date-picker v-model="form.year" placeholder="薪资年度" type="year" value-format="YYYY"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="薪资月份" prop="month">
						<el-select v-model="form.month" clearable filterable>
							<el-option value="1" label="一月"></el-option>
							<el-option value="2" label="二月"></el-option>
							<el-option value="3" label="三月"></el-option>
							<el-option value="4" label="四月"></el-option>
							<el-option value="5" label="五月"></el-option>
							<el-option value="6" label="六月"></el-option>
							<el-option value="7" label="七月"></el-option>
							<el-option value="8" label="八月"></el-option>
							<el-option value="9" label="九月"></el-option>
							<el-option value="10" label="十月"></el-option>
							<el-option value="11" label="十一月"></el-option>
							<el-option value="12" label="十二月"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="岗位工资" prop="postSalary">
						<el-input-number v-model="form.postSalary" placeholder="岗位工资"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="薪级工资" prop="levelSalary">
						<el-input-number v-model="form.levelSalary" placeholder="薪级工资"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="粮油补贴" prop="foodSalary">
						<el-input-number v-model="form.foodSalary" placeholder="粮油补贴"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="特殊岗位津贴" prop="otherPassSalary">
						<el-input-number v-model="form.otherPassSalary" placeholder="特殊岗位津贴"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="交通补贴" prop="transportSalary">
						<el-input-number v-model="form.transportSalary" placeholder="交通补贴"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="岗位津贴" prop="postAllowance">
						<el-input-number v-model="form.postAllowance" placeholder="岗位津贴"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="应发合计" prop="sumAmount">
						<el-input-number v-model="form.sumAmount" placeholder="应发合计"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="退休金" prop="pensoin">
						<el-input-number v-model="form.pensoin" placeholder="退休金"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="失业保险" prop="unemployment">
						<el-input-number v-model="form.unemployment" placeholder="失业保险"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="医保" prop="medical">
						<el-input-number v-model="form.medical" placeholder="医保"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="公积金" prop="accumulationFund">
						<el-input-number v-model="form.accumulationFund" placeholder="公积金"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="个人所得税" prop="tax">
						<el-input-number v-model="form.tax" placeholder="个人所得税"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="其它费用" prop="costOther">
						<el-input-number v-model="form.costOther" placeholder="其它费用"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="实扣费用" prop="realCost">
						<el-input-number v-model="form.realCost" placeholder="实扣费用"></el-input-number>
						/元
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="实发工资" prop="realSalary">
						<el-input-number v-model="form.realSalary" placeholder="实发工资"></el-input-number>
						/元
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明">
				<el-input v-model="form.remark" placeholder="备注说明" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
			<msg-box-check-box v-model:msgType="form.msgType" code="hr-salary"></msg-box-check-box>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectHrUserDialog from "@/views/module/selectHrUserDialog";
import msgBoxCheckBox from "@/views/module/msgBoxCheckBox";

export default {
	emits: ['success', 'closed'],
	components: {
		selectHrUserDialog,
		msgBoxCheckBox
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			btName: "保存",
			titleMap: {
				add: '添加薪资记录',
				edit: '编辑薪资记录',
				show: '查看'
			},
			fileList: [],
			apiObj: this.$API.file.attach.uploadFile,
			templateList: [],
			templates: [],
			form: {
				recordId: "",
				sortNo: 0,
				userId: "",
				year: "",
				month: "",
				postSalary: 0,
				levelSalary: 0,
				foodSalary: 0,
				otherPassSalary: 0,
				transportSalary: 0,
				postAllowance: 0,
				sumAmount: 0,
				pensoin: 0,
				unemployment: 0,
				medical: 0,
				accumulationFund: 0,
				tax: 0,
				costOther: 0,
				realCost: 0,
				realSalary: 0,
				msgType: "",
				remark:""
			},
			rules: {
				userId: [
					{required: true, message: '人员不能为空', trigger: 'change'}
				],
				year: [
					{required: true, message: '薪资年度不能为空'}
				],
				mouth: [
					{required: true, message: '薪资月份不能为空'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.hr.hrSalary.insertHrSalaryRecord.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.hr.hrSalary.updateHrSalaryRecord.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.sortNo = data.sortNo
			this.form.userId = data.userId
			this.form.year = data.year
			this.form.month = data.month
			this.form.postSalary = data.postSalary
			this.form.levelSalary = data.levelSalary
			this.form.foodSalary = data.foodSalary
			this.form.otherPassSalary = data.otherPassSalary
			this.form.transportSalary = data.transportSalary
			this.form.postAllowance = data.postAllowance
			this.form.sumAmount = data.sumAmount
			this.form.pensoin = data.pensoin
			this.form.unemployment = data.unemployment
			this.form.medical = data.medical
			this.form.accumulationFund = data.accumulationFund
			this.form.tax = data.tax
			this.form.costOther = data.costOther
			this.form.realCost = data.realCost
			this.form.realSalary = data.realSalary
			this.form.msgType = data.msgType
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
